package TAIC.util ;

import java.nio.channels.*;
import java.util.* ;
import java.io.* ;

class CopyImage {

	public static void main ( String s [] ) {
		if ( s.length < 1 ) {
			System.out.println ( "please input file name~~" ) ; 
			return ;
		}
		if ( s.length == 1 ) ( new CopyImage ()).copyImages ( s [ 0 ] , 0 ) ; 
		else ( new CopyImage ()).copyImages ( s [ 0 ] , 1 ) ; 
	}

	void copyImages ( String config , int x ) {
		try {
			int count = 0 ; 
			Scanner scanner = new Scanner ( new File ( config )) ; 
			while ( scanner.hasNextInt () ) {
				scanner.nextInt () ;  scanner.nextInt () ;
				String s = scanner.nextLine().trim() ;
				if ( x == 0 )copyFile ( s, "tempImage\\" + count + s.substring ( s.lastIndexOf ( '.' ) ) ) ;
				else copyFile ( s, "tempImage\\" + s.substring ( s.lastIndexOf ( '\\' ) ) ) ;
				count ++ ;
			}
		}catch ( Exception e ) {
			e.printStackTrace() ; 
		}
	}
	
	public static boolean copyFile( String a , String b ) //  Source and Destination
    {
    	boolean done= true ;
		File in = new File ( a );
		File out = new File ( b ) ;
		FileChannel inChannel = null;
		FileChannel outChannel = null;
        try {
    	
        inChannel = new
            FileInputStream(in).getChannel();
        outChannel = new
            FileOutputStream(out).getChannel();
            inChannel.transferTo(0, inChannel.size(),
                    outChannel);
        } 
        catch (IOException e) {
            //e.printStackTrace () ;
            done =  false ;
        }
        finally {           
			return done ;
        }
    }	
}